#!/bin/bash

if [ $# = 0 ]
then
echo
echo "makeUSmask script"
echo
echo "generate a mask for an US image. "
echo
echo "1. Convert from vpx to isi-format"
echo "2. Threshold (in fact this goes automatically in the next step)"
echo "3. Dilate with radius 1"
echo "4. Erode with radius 3"
echo "5. Dilate with radius 1"
echo "6. Convert from bitmap to isi-format"
echo "7. Convert from isi-format to vpx"
echo
echo "Usage:"
echo "makeUSmask"
echo "  <USfilename.vpx>"
echo 
echo "The mask is saved as USfilenamemask.vpx"
echo
echo NB: this script uses programs by Rashindra.
echo
exit 64
fi

vpxje=$1
vpxname=${vpxje%.vpx}
rashindrabin="/user/rashindra/bin/32b"

echo " 1. Convert from vpx to isi-format"
$rashindrabin/vpx2isi -i $vpxje -o $vpxname.temp1.isi
echo " 2. Threshold (in fact this goes automatically in the next step)"
echo " 3. Dilate with radius 1"
$rashindrabin/dilate -n 1 -k 3 -t 1 $vpxname.temp1.isi $vpxname.temp2.bm 
echo " 4. Erode with radius 3"
$rashindrabin/erode -n 1 -k 7 -t 1 $vpxname.temp2.bm $vpxname.temp3.bm 
echo " 5. Dilate with radius 1"
$rashindrabin/dilate -n 1 -k 3 -t 1 $vpxname.temp3.bm $vpxname.temp4.bm 
echo " 6. Convert from bitmap to isi-format"
$rashindrabin/bm2isi -i $vpxname.temp4.bm -o $vpxname.temp5.isi
echo " 7. Convert from isi-format to vpx"
$rashindrabin/isi2vpx -i $vpxname.temp5.isi -o "$vpxname""mask.vpx"

rm $vpxname.temp*.*



